package com.ys.servers.common.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by taotao on 2017/5/8.
 */
public abstract interface TimeUtils {

    /*public static long dailyInternal =86400000;
    public static long weeklyInternal =604800000;
    public static long monthlyInternal =*/


    static boolean today(long lastUpdate) {
        return lastUpdate >= getDailyStart();
    }

    static boolean thisWeek(long lastUpdate) {
        return lastUpdate >= getWeeklyStart();
    }

    static boolean thisMonth(long lastUpdate) {
        return lastUpdate >= getMonthlyStart();
    }

    static boolean continuousDay(long lastUpdate) {
        return (lastUpdate <= getDailyStart()) && (lastUpdate >= getDailyStart() - 24 * 3600 * 1000);
    }

    static String getTimeDescWithYYYYMMDD(long startTime, long endTime) {
        return getTimeDescWithYYYYMMDD(startTime) + "~" + getTimeDescWithYYYYMMDD(startTime, endTime);
    }

    static String getTimeDescWithYYYYMMDD(long startTime) {
        return new SimpleDateFormat("yyyy-MM-dd")
                .format(new Date(startTime));
    }

    static String getDateTimeWithYYMMDDHHMMSS(long time) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(new Date(time));
    }

    static long getDailyStart() {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime().getTime();
    }

    // 获得本周一0点时间
    static long getWeeklyStart() {
        Calendar cal = Calendar.getInstance();
        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        return cal.getTime().getTime();
    }

    // 获得本月第一天0点时间
    static long getMonthlyStart() {
        Calendar cal = Calendar.getInstance();
        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
        return cal.getTime().getTime();
    }
}
